import { defineConfig, loadEnv, ConfigEnv } from 'vite';
import vue from '@vitejs/plugin-vue';
import path from 'path';
// import eslintPlugin from 'vite-plugin-eslint';

const resolve = (dir: string) => path.join(__dirname, dir);
// const root = process.cwd();

// https://vitejs.dev/config/
const viteConfig = defineConfig((mode: ConfigEnv) => {
  const env = loadEnv(mode.mode, process.cwd());
  return {
    base: env.VITE_PUBLIC_PATH, // 生产环境路径配置
    server: {
      host: true,
      port: 3000,
      proxy: {
        '/picImageServer/': {
          target: 'http://10.40.23.148:9131/picImageServer',
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/picImageServer/, ''),
        },
      },
    },
    plugins: [
      vue(),
      // eslintPlugin({
      //   include: ['src/**/*.ts', 'src/**/*.vue', 'src/*.ts', 'src/*.vue'],
      // }),
    ],
    resolve: {
      alias: {
        '@': resolve('src'),
        '/@': resolve('src'),
        comps: resolve('src/components'),
        apis: resolve('src/apis'),
        views: resolve('src/views'),
        utils: resolve('src/utils'),
        routes: resolve('src/routes'),
        styles: resolve('src/styles'),
      },
    },
    css: {
      preprocessorOptions: {
        less: {
          javascriptEnabled: true,
        },
      },
    },
  };
});

export default viteConfig;
